import {
	defineStore
} from "pinia";
import store from "@/store";

export const useStore = defineStore('app', {
	state: () => {
		return {
			showLoginPopup: false,
			token: uni.getStorageSync("token") || "",
			userInfo: uni.getStorageSync("userInfo") || {},
		};
	},
	actions: {
		OPEN_LOGIN_POPUP() {
			this.showLoginPopup = true;
		},
		CLOSE_LOGIN_POPUP() {
			this.showLoginPopup = false;
		},
		SET_TOKEN(token) {
			this.token = token;
			uni.setStorageSync("token", token);
		},
		CLEAR_TOKEN() {
			this.token = "";
			uni.removeStorageSync("token");
		},
		SET_USERINFO(userInfo) {
			this.userInfo = userInfo;
			uni.setStorageSync("userInfo", userInfo);
		},
		CLEAR_USERINFO() {
			this.userInfo = "";
			uni.removeStorageSync("userInfo");
		},
	},
});


export default () => useStore(store);